package command;

import command.command.Command;
import command.command.impl.*;
import command.receiver.Light;
import command.receiver.TV;

/**
 * 命令模式客户端代码
 *
 * @author Liu Yicong
 * @date 2025/9/25
 */
public class CmdClient {
	public static void main(String[] args) {
		// 创建接收者
		Light livingRoomLight = new Light();
		TV myTV = new TV(false); // 初始状态下电视是关闭状态

		// 创建具体命令，并传入接收者
		Command lightOn = new TurnOnLightCommand(livingRoomLight);
		Command lightOff = new TurnOffLightCommand(livingRoomLight);
		Command TVOn = new TurnOnTVCommand(myTV);
		Command TVOff = new TurnOffTVCommand(myTV);
		Command TVUp = new VolUpTVCommand(myTV);
		Command TVDown = new VolDownTVCommand(myTV);

		// 创建调用者 (遥控器)
		RemoteControl remote = new RemoteControl();

		// --- 开灯 ---
		remote.setCommand(lightOn);
		remote.pressButton();

		// -- 降低电视音量 ---
		remote.setCommand(TVDown);
		remote.pressButton();


		// -- 开电视 ---
		remote.setCommand(TVOn);
		remote.pressButton();

		// -- 提高电视音量 ---
		remote.setCommand(TVUp);
		remote.pressButton();

		// --- 关灯 ---
		remote.setCommand(lightOff);
		remote.pressButton();

		// -- 降低电视音量 --
		remote.setCommand(TVDown);
		remote.pressButton();

		// -- 关电视 ---
		remote.setCommand(TVOff);
		remote.pressButton();

	}
}
